home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / boss.arc / GENINDEX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-29  |  2.0 KB  |  69 lines

  1. /*
  2. ** GENINDEX - Create index from text file.
  3. ** 
  4. ** Support Program for The Window BOSS
  5. **
  6. ** Copyright (c) 1984,1985,1986 - Philip A. Mongelluzzo
  7. ** All rights reserved.
  8. **
  9. ** Note: The GENINDEX.EXE file was created using the CI86 compiler.
  10. **       If you attempt to recompile this program with either Lattice
  11. **       or MSC you may have to adjust the logic to account for the way
  12. **       the various compilers treat <CR><LF> sequences.  This usually
  13. **       amounts to nothing more than chaning the "rb" to "r" in the
  14. **       fopen statement.  
  15. */
  16.  
  17. #include <stdio.h>                      /* Standard stuff */
  18.  
  19. FILE *fopen();                          /* keep the compilers happy */
  20. long ftell();
  21.  
  22. main(argc,argv)
  23. int argc;
  24. char *argv[];
  25. {
  26. FILE *fp;
  27. FILE *fo;
  28. char buf[132];
  29. static char fname[132];
  30. unsigned i;
  31. long pos;
  32. char *p;
  33.  
  34.   if(argc < 2) {                        /* check command line */
  35.     printf("Usage: genindex <filename.ext>");
  36.     exit(1);
  37.   }
  38.  
  39.   p = argv[1];                          /* parse input filename */
  40.   i = 0;
  41.   while(*p) {
  42.     fname[i++] = *p++;
  43.     if(*p == ' ' || *p == '.') break;
  44.   }
  45.   strcat(fname, ".ndx");                /* create output filename */
  46.  
  47.   fp = fopen(argv[1], "rb");            /* open input */
  48.   if(!fp) {
  49.     printf("Open failed: %s", argv[1]);
  50.     exit(1);
  51.   }
  52.   printf("Creating: %s\n", fname);      /* say whats going on */
  53.   fo = fopen(fname, "w");               /* open output */
  54.  
  55.   while(fgets(&buf[0],132,fp)) {        /* read lines till eof */
  56.     if(buf[0] == '%') {                 /* look for subject heading key */
  57.       fputs(buf, fo);                   /* write to index file */
  58.       fputs(buf, stdout);               /* display on console */
  59.       pos = ftell(fp);                  /* get file position */
  60.       printf("%ld\n", pos);             /* display on console */
  61.       fprintf(fo, "%ld\n", pos);        /* write in output file */
  62.     }
  63.   }
  64.   fclose(fp);                           /* close files */
  65.   fclose(fo);
  66. }
  67.  
  68. /* End */
  69.